<?php

//require_once(dirname(__FILE__).'/../../../../../plugins/sfGuardPlugin/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php');
require_once(sfConfig::get('sf_plugins_dir') . '/sfGuardPlugin/modules/sfGuardAuth/lib/BasesfGuardAuthActions.class.php');

class sfGuardAuthActions extends BasesfGuardAuthActions
{

  public function executeChangePassword() {
  }

  public function executeUpdatePassword() {
    $this->getUser()->getGuardUser()->setPassword($this->getRequestParameter('new_password'));
    $this->getUser()->getGuardUser()->save();
    $this->getUser()->setFlash('message', 'Het wachtwoord is gewijzigd.');
    $this->forward('sfGuardAuth', 'changePassword');
  }

  public function validateUpdatePassword() {
    $old_password  = $this->getRequestParameter('old_password');
    $new_password  = $this->getRequestParameter('new_password');
    $new_password2 = $this->getRequestParameter('new_password2');
    if (!$this->getUser()->checkPassword($old_password)) {
      $this->getRequest()->setError('password', 'Het oude wachtwoord is niet correct.');
      return false;
    } elseif ($new_password == $this->getUser()->getGuardUser()->getUsername()) {
      $this->getRequest()->setError('password', 'Het wachtwoord moet verschillen van de gebruikersnaam.');
      return false;
    } elseif ($new_password != $new_password2) {
      $this->getRequest()->setError('password2', 'De ingevoerde wachtwoorden komen niet overeen.');
      return false;
    }
    return true;
  }

  public function handleErrorUpdatePassword() {
    $this->forward('sfGuardAuth', 'changePassword');
  }
}
